﻿using System;
using Glue;
using Xunit;

namespace GlueTests.MapperVerificationTests
{
    public class When_mapping_simplified_nested_relations
    {
        private readonly Mapping<DomainPerson, GuiPerson> mapping;

        public class GuiPerson { public GuiAddress Address { get; set; } }
        public class GuiAddress { public String City { get; set; } }

        public class DomainPerson { public DomainAddress Address { get; set; } }
        
        public class DomainAddress
        {
            private String city = "";
            public String City
            {
                get { return city; }
                set { return;}
            }
        }

        public When_mapping_simplified_nested_relations()
        {
            mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.Relate(domain => domain.Address.City, gui => gui.Address.City);
        }

        [Fact]
        public void Should_verify()
        {
            mapping.GetMapperVerification().AssertMapsCorrectlyTowards(new GuiPerson{Address = new GuiAddress()});
        }

        [Fact]
        public void Should_fail_if_property_misbehaves()
        {
            Assert.Throws<GlueException>(() =>
                    mapping.GetMapperVerification().AssertMapsCorrectlyTowards(new DomainPerson { Address = new DomainAddress() })
                );
        }
    }
}
